<?php
class LoaicdsvsController extends AppController {

	var $name = 'Loaicdsvs';

	function index() {
		$this->Loaicdsv->recursive = 0;
		$this->set('loaicdsvs', $this->paginate());
	}
    
    function update(){
        $cd=$this->Session->read('chidoanht_id');
        $hk=$this->getHocKyHt();
        $loaicd=$this->Loaicdsv->find('first',array('hocky_id'=>$hk['Hocky']['id'],'chidoansv_id'=>$cd));
        $xeploaicd=$this->data['Loaicdsv']['xeploaicd_id'];
        if($loaicd['Loaicdsv']['duyet']==0){
            $this->Loaicdsv->updateAll(array('xeploaicd_id'=>$xeploaicd),array('hocky_id'=>$hk['Hocky']['id'],'chidoansv_id'=>$cd));
            $this->redirect(array('controller'=>'phanloaisvs','action' => 'index'));    
        }else {
            $this->Session->setFlash(__('Da khoa!', true));
        }
        
        
    }

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid loaicdsv', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('loaicdsv', $this->Loaicdsv->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Loaicdsv->create();
			if ($this->Loaicdsv->save($this->data)) {
				$this->Session->setFlash(__('The loaicdsv has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The loaicdsv could not be saved. Please, try again.', true));
			}
		}
		$xeploais = $this->Loaicdsv->Xeploai->find('list');
		$chidoansvs = $this->Loaicdsv->Chidoansv->find('list');
		$hockies = $this->Loaicdsv->Hocky->find('list');
		$this->set(compact('xeploais', 'chidoansvs', 'hockies'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid loaicdsv', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Loaicdsv->save($this->data)) {
				$this->Session->setFlash(__('The loaicdsv has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The loaicdsv could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Loaicdsv->read(null, $id);
		}
		$xeploais = $this->Loaicdsv->Xeploai->find('list');
		$chidoansvs = $this->Loaicdsv->Chidoansv->find('list');
		$hockies = $this->Loaicdsv->Hocky->find('list');
		$this->set(compact('xeploais', 'chidoansvs', 'hockies'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for loaicdsv', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Loaicdsv->delete($id)) {
			$this->Session->setFlash(__('Loaicdsv deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Loaicdsv was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
